package examples
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import com.wskeee.ec.components.Button;
	import com.wskeee.ec.components.CheckBox;
	import com.wskeee.ec.components.Label;
	import com.wskeee.ec.components.RadioButton;
	import com.wskeee.ec.components.RadioButtonGroup;
	import com.wskeee.ec.containers.Container;
	import com.wskeee.ec.containers.GridBox;
	import com.wskeee.ec.containers.HBox;
	import com.wskeee.ec.containers.VBox;
	
	public class ContainerExample extends Sprite
	{
		public function ContainerExample()
		{
			super();
		}
		
		public static function createVBox():Container
		{
			var mainBox:VBox = new VBox();
			var head:Label = new Label();
			head.text = "VBox";
			mainBox.paddingTop = mainBox.paddingBottom = mainBox.paddingLeft = mainBox.paddingRight = 5;
			mainBox.verticalGap = 20;
			mainBox.addChild(head);
			//---------------------
			//VBox
			//---------------------
			var content:VBox = new VBox();
			content.borderColor = 0xff0000;
			content.border = true;
			var button:Button;
			content.addChild(new RadioButton());
			for(var i:int=0;i<3;i++)
			{
				button = new Button();
				button.label = "wskeee"+Math.round(Math.random()*10000);
				content.addChild(button);
			}
			content.addChild(new CheckBox());
			button = new Button();
			button.width = 100;
			content.addChild(button);
			mainBox.addChild(content);
			//---------------------
			//control
			//---------------------
			var labels:Array = ["left","center","right"];
			var lastControlButton:Button;
			var controlBox:HBox = new HBox();
			for(i=0;i<3;i++)
			{
				button = new Button();
				button.toggle =true;
				button.label = labels[i];
				button.selected = false;
				button.addEventListener(MouseEvent.CLICK,changeVBoxHAlign);
				controlBox.addChild(button);
			}
			mainBox.addChild(controlBox);
			lastControlButton = controlBox.getChildAt(0) as Button;
			lastControlButton.selected = true;
			function changeVBoxHAlign(evt:Event):void
			{
				if(lastControlButton!=evt.currentTarget && lastControlButton)
					lastControlButton.selected = false;
				content.horizontalAlign = evt.currentTarget.label;
				lastControlButton = evt.currentTarget as Button;
			}
			
			return mainBox;
		}
		
		
		
		public static function createHBox():Container
		{
			var mainBox:VBox = new VBox();
			var head:Label = new Label();
			head.text = "HBox";
			mainBox.verticalGap = 20;
			mainBox.paddingTop = mainBox.paddingBottom = mainBox.paddingLeft = mainBox.paddingRight = 5;
			mainBox.addChild(head);
			
			var content:HBox = new HBox();
			content.borderColor = 0xff0000;
			content.border = true;
			var button:Button;
			content.addChild(new RadioButton());
			for(var i:int=0;i<1;i++)
			{
				button = new Button();
				button.label = "wskeee";
				content.addChild(button);
			}
			content.addChild(new CheckBox());
			button = new Button();
			button.height = 70;
			content.addChild(button);
			mainBox.addChild(content);
			//---------------------
			//control
			//---------------------
			var labels:Array = ["top","middle","bottom"];
			var lastControlButton:Button;
			var controlBox:HBox = new HBox();
			for(i=0;i<3;i++)
			{
				button = new Button();
				button.toggle =true;
				button.label = labels[i];
				button.selected = false;
				button.addEventListener(MouseEvent.CLICK,changeVBoxHAlign);
				controlBox.addChild(button);
			}
			mainBox.addChild(controlBox);
			lastControlButton = controlBox.getChildAt(0) as Button;
			lastControlButton.selected = true;
			function changeVBoxHAlign(evt:Event):void
			{
				if(lastControlButton!=evt.currentTarget && lastControlButton)
					lastControlButton.selected = false;
				
				content.verticalAlign = evt.currentTarget.label;
				lastControlButton = evt.currentTarget as Button;
			}
			return mainBox;
		}
		
		
		public static function createGridbox():Container
		{
			var mainBox:VBox = new VBox();
			var head:Label = new Label();
			head.text = "GridBox";
			mainBox.verticalGap = 20;
			mainBox.paddingTop = mainBox.paddingBottom = mainBox.paddingLeft = mainBox.paddingRight = 5;
			mainBox.addChild(head);
			
			var content:GridBox = new GridBox(3);
			content.borderColor = 0xff0000;
			content.border = true;
			var button:Button;
			content.addChild(new RadioButton());
			for(var i:int=0;i<6;i++)
			{
				button = new Button();
				button.label = "wskeee";
				button.width = 50+Math.round(Math.random()*50);
				button.height = 20+Math.round(Math.random()*50);
				content.addChild(button);
			}
			content.addChild(new CheckBox());
			button = new Button();
			button.width = 100;
			button.height = 30;
			content.addChild(button);
			mainBox.addChild(content);
			//---------------------
			//control
			//---------------------
			var valignLabels:Array = ["top","middle","bottom"];
			var halignLabels:Array = ["left","center","right"];
			var rb:RadioButton;
			var valignGroup:RadioButtonGroup = new RadioButtonGroup("valignGroup");
			var halignGroup:RadioButtonGroup = new RadioButtonGroup("halignGroup");
			var controlBox:HBox = new HBox();
			//valignLabels
			var controlSubBox:HBox = new HBox();
			for(i=0;i<3;i++)
			{
				rb = new RadioButton();
				rb.label = valignLabels[i];
				rb.groupName = "valignGroup";
				controlSubBox.addChild(rb);
			}
			controlBox.addChild(controlSubBox);
			//halignLabels
			controlSubBox = new HBox();
			for(i=0;i<3;i++)
			{
				rb = new RadioButton();
				rb.label = halignLabels[i];
				rb.groupName = "halignGroup";
				controlBox.addChild(rb);
			}
			controlBox.addChild(controlSubBox);
			
			button = new Button();
			button.label = "autSize";
			button.toggle = true;
			button.addEventListener(Event.CHANGE,function(evt:Event):void
			{
				content.autoSize = button.selected;
			});
			controlBox.addChild(button);
			
			mainBox.addChild(controlBox);
			valignGroup.addEventListener(Event.CHANGE,function(evt:Event):void
			{
				content.verticalAlign = valignGroup.value.toString();
			});
			halignGroup.addEventListener(Event.CHANGE,function(evt:Event):void
			{
				content.horizontalAlign = halignGroup.value.toString();
			});
			
			return mainBox;
		}
	}
}